package cn.jinhe.doc.view.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.jinhe.doc.base.BaseAction;
import cn.jinhe.doc.domain.PcInfo;
import cn.jinhe.doc.util.PingTest;
import cn.jinhe.doc.util.QueryHelper;

@Controller
@Scope("prototype")
public class PcInfoAction extends BaseAction<PcInfo>{
	
	public String show() throws Exception {
		
		PingTest pingTest=new PingTest();
		// 准备数据:topic
		
		PcInfo pcInfo = pcInfoService.getById(model.getId());
		pcInfo.setIpAddress(pingTest.ipGet(pcInfo.getPcName()));
		ActionContext.getContext().put("pcInfo", pcInfo);
		
		
		return "show";	
	}
	
	
	public String list() throws Exception {
		//List<User> userList = userService.findAll();
		//ActionContext.getContext().put("userList", userList);
		
		//准备分页信息
		new QueryHelper(PcInfo.class, "p").preparePageBean(pcInfoService, pageNum, pageSize);
		
		return "list";
	}
	/*
	 * 删除
	 */
	public String delete() throws Exception {
		pcInfoService.delete(model.getId());
		return "toList";
	}

	/*
	 * 添加
	 */
	public String add() throws Exception {
		
/*		model.setDepartment(departmentService.getById(departmentId));
		List<Role> roleList=roleService.getByIds(roleIds);
		model.setRoles(new HashSet<Role>(roleList));
//		model.setRoles(new ArrayList().addAll(roleList));
		
		String md5Digest=DigestUtils.md5Hex("1234");
		model.setPassword(md5Digest);*/
//		model.setStore((long) 0);
		pcInfoService.save(model);

		return "toList";
	}

	/*
	 * 添加页面
	 */
	public String addUI() throws Exception {
		List<PcInfo> pcInfoList=pcInfoService.findAll();
		
		ActionContext.getContext().put("pcInfoList", pcInfoList);
		return "saveUI";	
	}

	/*
	 * 修改页面
	 */
	public String editUI() throws Exception {
		
		PcInfo pcInfo=pcInfoService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(pcInfo);
		return "saveUI";
	}

	/*
	 * 修改
	 */
	public String edit() throws Exception {
		//1,从数据库中取出原对象
		PcInfo pcInfo=pcInfoService.getById(model.getId());
		
		//2，设置要修改的属性
	
		pcInfoService.update(pcInfo);
		
		return "toList";
	}
}
